package com.gaswell.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gaswell.entity.Qba01M;
import com.gaswell.mapper.ModbusLogMapper;
import com.gaswell.mapper.Qba01MMapper;
import com.gaswell.pojo.ModbusLog;
import com.gaswell.service.ModbusLogService;
import com.gaswell.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@DS("mysql")
public class ModbusLogServiceImpl extends ServiceImpl<ModbusLogMapper, ModbusLog> implements ModbusLogService {
    @Autowired
    private ModbusLogMapper modbusLogMapper;

    @Override
    public Result selectAll(int current, int size) {
        Page<ModbusLog> page = new Page<>(current, size);
        LambdaQueryWrapper<ModbusLog> modbusLogLambdaQueryWrapper = new LambdaQueryWrapper<>();
        modbusLogLambdaQueryWrapper.orderByDesc(ModbusLog::getTime);
        modbusLogMapper.selectPage(page, modbusLogLambdaQueryWrapper);
        return new Result(true, 200, "success", page.getRecords(), (int) page.getTotal(), (int) page.getPages());
    }

    @Override
    public Page selectAllByJh(int current, int size, String jh) {
        QueryWrapper<ModbusLog> modbusLogQueryWrapper = new QueryWrapper<>();
        modbusLogQueryWrapper.eq("jh", jh);
        modbusLogQueryWrapper.orderByDesc("time");
        Page<ModbusLog> page = new Page<>(current, size);
        Page<ModbusLog> modbusLogPage = modbusLogMapper.selectPage(page, modbusLogQueryWrapper);
        return modbusLogPage;
    }
}
